package pers.lan.th.java.joinyield;

/**
 * @author <p><a href="mailto:1728209643@qq.com">XiaoSan</a>
 * @date 2019/11/28 5:09 PM
 */
public class JoinYield {

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(new Mt());
        Thread t2 = new Thread(new Mt());
        t1.start();
        t1.join();
        t2.start();
        Thread t3 = new Thread(new Mt());
        t3.start();
    }

    static class Mt implements Runnable {
        public void run() {
            int i = 1;
            while (i++ % 6 != 0) {
                System.out.println(Thread.currentThread().getId());
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            if (System.currentTimeMillis() % 2 == 0) {
                System.out.println(Thread.currentThread().getId() + "===>");
                Thread.yield();
                System.out.println(Thread.currentThread().getId() + "<===");

            }
        }
    }

}
